package cn.kzgg.ymcc.controller;

import cn.kzgg.ymcc.doc.CourseDoc;
import cn.kzgg.ymcc.dto.CourseSearchDto;
import cn.kzgg.ymcc.result.JSONResult;
import cn.kzgg.ymcc.result.PageList;
import cn.kzgg.ymcc.service.ICourseEsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CourseEsController {

    @Autowired
    private ICourseEsService courseEsService;

    @PostMapping("/saveCourse")
    public JSONResult saveCourse(@RequestBody CourseDoc courseDoc){
        courseEsService.saveCourse(courseDoc);
        return JSONResult.success();
    }

    @PostMapping("/remCourse/{courseId}")
    public JSONResult remCourse(@PathVariable("courseId") Long courseId){
        courseEsService.remCourse(courseId);
        return JSONResult.success();
    }

    /**
     * 课程列表  Es分页查询
     * @param courseSearchDto
     * @return
     */
    @PostMapping("/course/search")
    public PageList<CourseDoc> search(@RequestBody CourseSearchDto courseSearchDto){
        return courseEsService.search(courseSearchDto);
    }
}
